package com.bdqn.t362.order.dao.impl;

import com.bdqn.t362.common.dao.BaseDao;
import com.bdqn.t362.order.dao.TB2COrderDao;
import com.bdqn.t362.order.entity.TB2COrder;
import com.bdqn.t362.order.entity.TProduct;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author lqm
 * @ClassName TB2COrderDaoImpl
 * @description: TODO
 */
public class TB2COrderDaoImpl extends BaseDao implements TB2COrderDao {


    @Override
    public int addOrder(TB2COrder tb2COrder) {
        String sqlStr ="insert into order (order_code,create_time,sum_amount) values(?,now(),?)";
        return executeInsert(sqlStr,tb2COrder.getOrderCode(),tb2COrder.getSumAmout());
    }

    @Override
    public TB2COrder getOrderByOrderCode(String orderCode) {
        String sqlStr="select * from order where order_code=?";
        TB2COrder result = null;
        ResultSet rs = executeQuery(sqlStr,orderCode);

            try {
                while (rs.next()){
                    result=new TB2COrder();
                    result.setId(rs.getInt(1));

                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }


        return result;
    }

    @Override
    public int updateOrder(String orderCode, String payStatus) {
        String sqlStr="update order set order_status =? where order_code=?";
        return executeUpdate(sqlStr,orderCode,payStatus);
    }

    @Override
    public List<TProduct> getProductList() {

        return null;
    }
}
